package greedy;

/**
 * Created by JiaJia on 2019/8/12 0012.
 */
public class Subsequence {
    public static void main(String[] args) {
        String s="abc";
        String t="ahdbdidcj";
        System.out.println(isSubsequence(s,t));
    }
    /*public static boolean isSubsequence(String s, String t) {
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c, index + 1);
            if (index == -1) {
                return false;
            }
        }
        return true;
    }*/
    public static boolean isSubsequence(String s, String t){
        int sbegin=0,tbegin=0;
        while (sbegin<s.length()&&tbegin<t.length()){
            if (s.charAt(sbegin)==t.charAt(tbegin)){
                sbegin++;
                tbegin++;
            }else {
                tbegin++;
            }
        }
        return sbegin==s.length();
    }
}